import json
from flask import Blueprint, request, jsonify

from database import db

user_bp = Blueprint('user', __name__)


@user_bp.route('/login/', methods=['POST', 'GET'])
def login():
    if request.method == "POST":
        data = json.loads(request.data)
        mobile = data['mobile']
        password = data['password']
        sql = 'select * from goods where mobile=%s' % (mobile)
        user = db.findone(sql)
        if user:
            if user and user['password'] == password:
                return jsonify({'code':200,'userid':user['id']})
            else:
                return jsonify({'code': 10011})
        else:
            return jsonify({'code': 10010})
    else:
        return '获取'
